'''
header的cookie

模拟登录  处理cookie
代理 --》 防止被封IP

'''
import requests

'''
17K  登录，拿到cookie  去请求书架url获取书架上内容
session过程中cookie不丢失

'''
# 浏览器有缓存，这里没有  运行一次有
session = requests.session()
data = {
    "loginName":"13112387261",
    "password":"987654aaa"
}
url = "https://passport.17k.com/ck/user/login"
resp = session.post(url,data=data)
print(resp.cookies)
# <RequestsCookieJar[<Cookie accessToken=avatarUrl%3Dhttps%253A%252F%252Fcdn.static.17k.com%252Fuser%252Favatar%252F01%252F21%252F46%252F76944621.jpg-88x88%253Fv%253D1620288032000%26id%3D76944621%26nickname%3D%25E4%25B9%25A6%25E5%258F%258B%25E6%2598%25B5%25E7%25A7%25B0%25E5%25B7%25B2%25E5%25AD%2598%25E5%259C%25A8%26e%3D1635842378%26s%3Df831b68e24830cf7 for .17k.com/>, <Cookie c_channel=0 for .17k.com/>, <Cookie c_csc=web for .17k.com/>, <Cookie uuid=1C625D52-1CD0-DB88-B488-AC93FC401B76 for .17k.com/>]>


#  request.get(url) 会直接发送请求，不会知道我的cookie 使用 session.get()
# print(session.get().text)
# 或者你可以直接在浏览器复制cookie
# result = requests.get(url,headers={
#     "Cookie":"GUID=1b4ddc07-ea38-44a6-b5bc-29824702d670; sajssdk_2015_cross_new_user=1; Hm_lvt_9793f42b498361373512340937deb2a0=1620287782; c_channel=0; c_csc=web; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%221b4ddc07-ea38-44a6-b5bc-29824702d670%22%2C%22%24device_id%22%3A%2217940ad7c3421d-035d14f06c9dba-87f133f-2073600-17940ad7c35bab%22%2C%22props%22%3A%7B%7D%2C%22first_id%22%3A%221b4ddc07-ea38-44a6-b5bc-29824702d670%22%7D; Hm_lpvt_9793f42b498361373512340937deb2a0=1620289143; accessToken=avatarUrl%3Dhttps%253A%252F%252Fcdn.static.17k.com%252Fuser%252Favatar%252F01%252F21%252F46%252F76944621.jpg-88x88%253Fv%253D1620288032000%26id%3D76944621%26nickname%3D%25E4%25B9%25A6%25E5%258F%258B%25E6%2598%25B5%25E7%25A7%25B0%25E5%25B7%25B2%25E5%25AD%2598%25E5%259C%25A8%26e%3D1635841147%26s%3Daa5ba5878a6c9e1c"
# })
# print(result.text)
# {"status":{"code":1101,"msg":"用户不存在:0"},"time":1620290342000}



'''
防盗链    对视频新闻里的防盗链
页面不会存在img和链接  是后期用js脚本添加上的  如何找到：  检查--Network- XHR 刷新  链接如果直接浏览器访问也是404
如何破解？  一般是对链接的视频名字进行替换，而网站名和目录一般没变
仔细查看原始链接、network发现的链接，破解后链接  3个是有关联的
增加 User-Agent 和  Referer: https://user.17k.com/www/    Referer用于验证你是从哪里来的（本次请求的上一级是谁），   1，2，3   如果你在2访问，但是Referer不知道，正常是1

下载视频 和图片都是mode = "wb"
        with open(name,mode="wb") as f:
            f.write(request.get(url).content)
'''


'''
代理
原理：   通过第三方的一个机器去发送请求
https://www.zdaye.com/FreeIPList.html  免费代理  类型是透明的都可以用
'''
proxies ={
    "https": "https://218.60.8.83:3129"
}
resp = requests.get("https://www.baidu.com",proxies=proxies)
resp.encoding="utd-8"
print(resp.text)